<?php
/*=============================================================================
|| ##################################################################
||	phpFoX Konsort
|| ##################################################################
||	
||	Copyright		: (C) 2005-2007 PHPFOX Limited a Reality Fox Creation
||	Contact			: info@phpfox.com
||
||	- phpFoX and all of its source code and files are protected by Copyright Laws. 
||
||	- The license for phpFoX permits you to install this software on a single domain (.com, .org, .net, etc.). 
||
||	- You may also not remove this copyright screen which shows the copyright information and credits for phpFoX (RealityFOX Creations). 
||
||	- phpFoX Konsort is NOT a FREE software - http://www.phpfox.com/license/
||
|| ##################################################################
=============================================================================*/

/* $File: ./include/classes/smarty/plugins/modifier.filesize.php, $Author:  $ */

function smarty_modifier_filesize($iSize, $iPrecision = 2)
{
    if (!is_numeric($iSize))
        return $iSize;

    if (!is_numeric($iPrecision))
        $iPrecision = 2;
    $sSize   = '';
    $fSize   = 0;
    $sSuffix = '';

    if ($iSize >= 1073741824)
    {
        $fSize = $iSize / 1073741824;
        $sSuffix = App::format('filesize.gigabyte');
    }
    elseif (($iSize >= 1048576) && ($iSize < 1073741824))
    {
        $fSize = $iSize / 1048576;
        $sSuffix = App::format('filesize.megabyte');
    }
    elseif (($iSize >= 1024) && ($iSize < 1048576))
    {
        $fSize = $iSize / 1024;
        $sSuffix = App::format('filesize.kilobyte');
    }
    else
    {
        $fSize = $iSize;
        $sSuffix = App::format('filesize.byte');
    }
    $sSize = round($fSize, $iPrecision);
    $sSize .= ' '.$sSuffix;
    return $sSize;
}
?>